﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.IO;
using DTBuilderLib;

namespace DeepTalkWF
{
    /// <summary>
    /// Look to see if the token for a talk si set. We can use this to short-circuit a
    /// re-download, etc.
    /// </summary>
	public partial class CheckForDZToken: Activity
	{
		public CheckForDZToken()
		{
			InitializeComponent();
		}

        /// <summary>
        /// Name of the meeting
        /// </summary>
        public string MeetingName
        {
            get { return (string)GetValue(MeetingNameProperty); }
            set { SetValue(MeetingNameProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MeetingName.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MeetingNameProperty =
            DependencyProperty.Register("MeetingName", typeof(string), typeof(CheckForDZToken), new PropertyMetadata(null));

        /// <summary>
        /// The directory where we are placing the output
        /// </summary>
        public DirectoryInfo DZDirectory
        {
            get { return (DirectoryInfo)GetValue(DZDirectoryProperty); }
            set { SetValue(DZDirectoryProperty, value); }
        }

        // Using a DependencyProperty as the backing store for DZDirectory.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DZDirectoryProperty =
            DependencyProperty.Register("DZDirectory", typeof(DirectoryInfo), typeof(CheckForDZToken), new PropertyMetadata(null));

        /// <summary>
        /// The result of the token check filled in after the activity executes.
        /// </summary>
        public bool DZTokenStatus
        {
            get { return (bool)GetValue(DZTokenStatusProperty); }
            set { SetValue(DZTokenStatusProperty, value); }
        }

        // Using a DependencyProperty as the backing store for DZTokenStatus.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DZTokenStatusProperty =
            DependencyProperty.Register("DZTokenStatus", typeof(bool), typeof(CheckForDZToken), new PropertyMetadata(false));


        /// <summary>
        /// Next, Look to see if we can find the token, and set our status.
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            DeepZoomBuilder bld = new DeepZoomBuilder();
            bld.BuildDirectory = DZDirectory.FullName;
            DZTokenStatus = bld.MeetingAlreadyRendered(MeetingName);

            return ActivityExecutionStatus.Closed;
        }
	}
}
